package by.grsu.bso.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LogoutAction extends Action {

	private final static String ORDER_FORWARD = "order_forward";
	private final static String PROFILE_CHANGE_FORWARD = "profile_change_forward";
	private final static String EXIT_FORWARD = "exit_forward";
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String profileOperation = request.getParameter("profile_operation");
		
		if (profileOperation.equals("profile_orders")) {
			
		} else if (profileOperation.equals("profile_change")){
			
		} else if (profileOperation.equals("profile_exit")) {
			
			HttpSession session = request.getSession(true);
			session.removeAttribute("user");
			response.sendRedirect(request.getContextPath());
			return mapping.findForward(EXIT_FORWARD);
			
		}
		return mapping.findForward(EXIT_FORWARD); //ERROR
	}
	

}
